//
//  TaskRateTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/3/10.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "TaskRateTableViewCell.h"

@interface TaskRateTableViewCell ()

// 任务评分
@property(nonatomic,strong)UILabel *titleLabel;

@property(nonatomic,strong)UILabel *rateLabel;

@property(nonatomic,strong)UIView *qualityRateView;

@property(nonatomic,strong)UIView *levelRateView;

@property(nonatomic,strong)UIView *attitudeRateView;

@property(nonatomic,strong)UILabel *memoLabel;

@end

@implementation TaskRateTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.titleLabel.font=Font_Number(15);

        self.memoLabel.font=Font_Number(14);

        self.backgroundColor=WhiteColor;

    }
    return self;
}

// titleLabel
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel=[self getLabelWithText:@"任务评分" font:Font_Number(15) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.top.mas_equalTo(kmargin*2);
        }];
    }
    return _titleLabel;
}

-(UIView *)qualityRateView
{
    if (!_qualityRateView) {
        _qualityRateView=[UIView new];
        [self.contentView addSubview:self.qualityRateView];
        [_qualityRateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*3));
            make.left.mas_equalTo(0);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(kmargin/2);
        }];

        UILabel *label=[self getLabelWithText:@"质      量" font:Font_Number(15) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.qualityRateView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.top.mas_equalTo(kmargin);
            make.width.mas_equalTo(APPW/4-kmargin*2);
        }];
    }
    return _qualityRateView;
}

// 效率
-(UIView *)levelRateView
{
    if (!_levelRateView) {
        _levelRateView=[UIView new];
        [self.contentView addSubview:self.levelRateView];
        [_levelRateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*3));
            make.left.mas_equalTo(0);
            make.top.mas_equalTo(self.qualityRateView.mas_bottom);
        }];

        UILabel *label=[self getLabelWithText:@"效      率" font:Font_Number(15) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.levelRateView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.top.mas_equalTo(kmargin);
            make.width.mas_equalTo(APPW/4-kmargin*2);
        }];
    }
    return _levelRateView;
}

// 态度
-(UIView *)attitudeRateView
{
    if (!_attitudeRateView) {
        _attitudeRateView=[UIView new];
        [self.contentView addSubview:self.attitudeRateView];
        [_attitudeRateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*3));
            make.left.mas_equalTo(0);
            make.top.mas_equalTo(self.levelRateView.mas_bottom);
        }];

        UILabel *label=[self getLabelWithText:@"态      度" font:Font_Number(15) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.attitudeRateView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.top.mas_equalTo(kmargin);
            make.width.mas_equalTo(APPW/4-kmargin*2);
        }];
    }
    return _attitudeRateView;
}

// memoLabel
- (UILabel *)memoLabel
{
    if (!_memoLabel) {
        UILabel *label=[self getLabelWithText:@"留      言" font:Font_Number(14) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.top.mas_equalTo(self.attitudeRateView.mas_bottom).offset(kmargin);
            make.width.mas_equalTo(APPW/4-kmargin*2);
        }];

        _memoLabel=[self getLabelWithText:@"留言" font:Font_Number(13) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_memoLabel];
        [_memoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(label.mas_right);
            make.centerY.mas_equalTo(label.mas_centerY);
        }];

    }
    return _memoLabel;
}


-(void)configCellWithRateDic:(NSDictionary *)rateDic
{
    self.memoLabel.text=rateDic[@"memo"];

    NSInteger qualityCount=[rateDic[@"quality"] integerValue];
    for (int i=0;i<qualityCount;i++)
    {
        UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(APPW/4+(i%qualityCount)*kmargin*3,kmargin,kmargin*3/2,kmargin*3/2)];
        [self.qualityRateView addSubview:image];
        image.image=[UIImage imageNamed:@"StarSelected"];
    }

    NSInteger efficientCount=[rateDic[@"efficient"] integerValue];
    for (int i=0;i<efficientCount;i++)
    {
        UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(APPW/4+(i%efficientCount)*kmargin*3,kmargin,kmargin*3/2,kmargin*3/2)];
        [self.levelRateView addSubview:image];
        image.image=[UIImage imageNamed:@"StarSelected"];
    }

    NSInteger attitudeCount=[rateDic[@"attitude"] integerValue];
    for (int i=0;i<attitudeCount;i++)
    {
        UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(APPW/4+(i%attitudeCount)*kmargin*3,kmargin,kmargin*3/2,kmargin*3/2)];
        [self.attitudeRateView addSubview:image];
        image.image=[UIImage imageNamed:@"StarSelected"];
    }

}

@end
